package main;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import draw.StdDraw;
import file_import.In;


public class Point implements Comparable<Point> {

	// compare points by slope to this point
	public final Comparator<Point> SLOPE_ORDER = new SlopeOrder();
	public final int x;
	public final int y;

	public Point(int x, int y) {
		this.x = x;
		this.y = y;		
	}

	public void draw() {
        StdDraw.point(this.x, this.y);
	}
	   
	public void drawTo(Point that) {
		StdDraw.line(this.x, this.y, that.x, that.y);
	}
   
	public String toString() {
		return "(" + x + ", " + y + ")";
	}

	public int compareTo(Point that) {
		if (this.y < that.y)
			return -1;
		else if (this.y > that.y)
			return 1;
		else if (this.y == that.y) {
			if (this.x < that.x)
				return -1;
			else if (this.x > that.x)
				return 1;
			else if (this.x == that.x)
				return 0;
		}
		return 2;
	}
   
	public double slopeTo(Point that) {
		if (this.x == that.x && this.y == that.y)
			return Double.NEGATIVE_INFINITY;
		return (double)(that.y - this.y)/(that.x - this.x);
	}
	
	private class SlopeOrder implements Comparator<Point> {

		@Override
		public int compare(Point q, Point r) {
			System.out.println("comparing...");
			double slope = Point.this.slopeTo(q);
			System.out.println("slope: "+slope);
			double slope1 = Point.this.slopeTo(r);
			System.out.println("slope1: "+slope1);
			if (slope == slope1)
				return 0;
			else if (slope > slope1)
				return 1;
			return -1;
		}
	}
	
	public static void main(String args[]) {
		Point p = new Point(10,10);
		Point p1 = new Point(20,20);
		p.drawTo(p1);
	}
}
